package com.fqgj.xjd.user.integration.ocr;

import com.alibaba.fastjson.JSONObject;
import com.fqgj.xjd.user.client.response.AadhaarBack;
import com.fqgj.xjd.user.client.response.AadhaarFrontBottom;
import com.fqgj.xjd.user.integration.ocr.vo.*;

import java.io.IOException;
import java.util.List;

/**
 * ·
 *
 * @author liuming
 * Created on 下午3:06 2018/9/11.
 */
public class Test {

    public static String panMock = "{\n" +
            "\t\"status\" : \"success\",\n" +
            "\t\"statusCode\" : \"200\",\n" +
            "\t\"result\" : [{\n" +
            "\t\t\"details\" : {\n" +
            "\t\t\t\"date\" : \"1990-01-12\",\n" +
            "\t\t\t\"father\" : \"Aaa Bbb\",\n" +
            "\t\t\t\"name\" : \"Ccc Bbb\",\n" +
            "\t\t\t\"pan_no\": \"1929394394\"\n" +
            "\t\t},\n" +
            "\t\t\"type\" : \"pan\"\n" +
            "\t}]\n" +
            "}";

    public static String aadhaarMock = "{\n" +
            "\t\"status\" : \"success\",\n" +
            "\t\"statusCode\" : \"200\",\n" +
            "\t\"result\" : [{\n" +
            "\t\t\"details\" : {\n" +
            "\t\t\t\"aadhaar\":\"aaaaa\",\n" +
            "\t\t\t\"dob\":\"1234-12-12\",\n" +
            "\t\t\t\"father\":\"CCC EEE\", \n" +
            "\t\t\t\"gender\":\"M\",\n" +
            "\t\t\t\"mother\":\"MMM AAA\",\n" +
            "\t\t\t\"name\": \"AAA CCC\",\n" +
            "\t\t\t\"yob\":\"1204\"\n" +
            "\t\t},\n" +
            "\t\t\"type\" : \"aadhaar_front_bottom\"\n" +
            "\t},{\n" +
            "\t\t\"details\" : {\n" +
            "\t\t\t\"aadhaar\":\"aaaaa\",\n" +
            "\t\t\t\"address\": \"sadfasfsfsa sdfas adsfa dasf\",\n" +
            "\t\t\t\"address_split\": {\n" +
            "\t\t\t\t\"care_of\":\"ASDS sdFASd\",\n" +
            "\t\t\t\t\"city\":\"DSF DSAF\",\n" +
            "\t\t\t\t\"line1\":\"sdafsfG sg ASDFs \",\n" +
            "\t\t\t\t\"line2\":\"SDGFAF sDFASWEE\",\n" +
            "\t\t\t\t\"pin\":\"213132\",\n" +
            "\t\t\t\t\"state\":\"DSSRTWE\"\n" +
            "\t\t\t},\n" +
            "\t\t\t\"father\": \"ASCXZ CXVG\",\n" +
            "\t\t\t\"husband\": \"SQWE GDS\",\n" +
            "\t\t\t\"name\": \"CHYY DSG\",\n" +
            "\t\t\t\"phone\": \"2394955696\",\n" +
            "\t\t\t\"pin\": \"123455\"\n" +
            "\t\t},\n" +
            "\t\t\"type\" : \"aadhaar_front_top\"\n" +
            "\t}\n" +
            "\t]\n" +
            "}";

    public static void main(String[] args) throws IOException {

        //System.out.println(new HyperDocs().requestMethod("https://cashmama-test.oss-cn-hangzhou.aliyuncs.com/clientSpace/test/180905996479000100/14d508e5-2c97-492b-a82d-3b3e46c7114b", HyperDocs.InputType.IMAGE, HyperDocs.EndPoint.READ_PAN));

        //System.out.println(OcrHttpPost.post("https://cashmama-test.oss-cn-hangzhou.aliyuncs.com/clientSpace/test/180905996479000100/14d508e5-2c97-492b-a82d-3b3e46c7114b"));
        //String responseJson = panMock;
        String panJson = new HyperDocs().requestMethod("" +
                        "" +
                        "http://cashmama-oss-pro.cashmama.in/clientSpace/2018091399006125001301/63f2f1f6-8b40-4393-b14b-38e9e5de7201",
                HyperDocs.InputType.IMAGE, HyperDocs.EndPoint.READ_AADHAAR);
        /*
        Pan pan = null;
        OcrSuccessResponse ocrSuccessResponse = JSONObject.parseObject(panJson, OcrSuccessResponse.class);
        String result = ocrSuccessResponse.getResult();
        if (result == null) {
            System.out.println("result == null ~!!!!!");
            return;
        }
        List<OcrSuccessResult> ocrSuccessResults = JSONObject.parseArray(result, OcrSuccessResult.class);
        for (OcrSuccessResult ocrSuccessResult : ocrSuccessResults) {
            if (ocrSuccessResult.getType().equals(KycTypeEnum.PAN.getType())
                    || ocrSuccessResult.getType().equals(KycTypeEnum.OLD_PAN.getType())) {
                String details = ocrSuccessResult.getDetails();
                pan = JSONObject.parseObject(details, Pan.class);
            }
        }
        if (pan != null) {
            System.out.println(pan.getDate());
            System.out.println(pan.getFather());
            System.out.println(pan.getName());
            System.out.println(pan.getPanNo());
        }
*/
        //responseJson = aadhaarMock;
        AadhaarFrontTop aadhaarFrontTop = null;
        AadhaarFrontBottom aadhaarFrontBottom = null;
        AadhaarBack aadhaarBack = null;
        OcrSuccessResponse ocrSuccessResponse = JSONObject.parseObject(panJson, OcrSuccessResponse.class);
        String result = ocrSuccessResponse.getResult();
        List<OcrSuccessResult> ocrSuccessResults = JSONObject.parseArray(result, OcrSuccessResult.class);
        for (OcrSuccessResult ocrSuccessResult : ocrSuccessResults) {
            if (ocrSuccessResult.getType().equals(KycTypeEnum.AADHAAR_FRONT_TOP.getType())) {
                String detail = ocrSuccessResult.getDetails();
                aadhaarFrontTop = JSONObject.parseObject(detail, AadhaarFrontTop.class);
                continue;
            }
            if (ocrSuccessResult.getType().equals(KycTypeEnum.AADHAAR_FRONT_BOTTOM.getType())) {
                String detail = ocrSuccessResult.getDetails();
                aadhaarFrontBottom = JSONObject.parseObject(detail, AadhaarFrontBottom.class);
                continue;
            }
            if (ocrSuccessResult.getType().equals(KycTypeEnum.AADHAAR_BACK.getType())) {
                String detail = ocrSuccessResult.getDetails();
                aadhaarBack = JSONObject.parseObject(detail, AadhaarBack.class);
                continue;
            }
        }


        if (aadhaarFrontTop != null) {
            System.out.println(1);
        }
        if (aadhaarFrontBottom != null) {
            System.out.println(1);
        }
    }
}
